module.exports = (app) => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const Conclusion = app.model.define('Conclusion', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    name: { type: STRING(255) },
    FKClassification: { type: INTEGER, field: 'fk_classification' },
    createdAt: { type: DATE, field: 'created_at' },
    updatedAt: { type: DATE, field: 'updated_at' },
  },
  {
    tableName: 'conclusions'
  });

  Conclusion.associate = () => {
    app.model.Conclusion.belongsTo(app.model.Classification, {
      foreignKey: 'fk_classification',
      targetKey: 'id',
    });

    app.model.Conclusion.hasMany(app.model.Feedback, {
      foreignKey: 'fk_conclusion',
      sourceKey: 'id',
    });

    app.model.Conclusion.belongsToMany(app.model.Question, {
      through: app.model.MergeQuestionConclusion,
      foreignKey: 'fk_conclusion',
      targetKey: 'id',
    });
  };

  return Conclusion;
};
